<?php
namespace DRY\Module;

/**
 * DonReY Framework 2012 :: Time delayed events manager.
 * Allows setting up "events" (which are actually method calls) that will happen sometime in the future.
 * Events are recorded in a database, so this module requires a record module to handle the data
 * Features -(planned) !(done) ~(partial):
 * - Add events at time (relative to Now or absolute)
 * - Auto-trigger stored events (and either mark them as triggered or remove them - Called method can return data which is stored in the event)
 * - Event cleaner
 *
 * @author Wavetrex <wavetrex@gmail.com>
 * @link http://www.donrey.net/Documentation/Structure/Modules/events.html
 * @license [GPL v3] http://www.gnu.org/licenses/gpl-3.0.html
 * @version 1.0.dev
 * @package DonReY
 * @subpackage Module/Events
 */
class Events extends base
{

	/**
	 * Sets the owner for all future event operations
	 * Example: The logged in user's ID
	 *
	 * @param int $owner_id If null, the event system doesn't use owners ( one single event list )
	 */
	public function set_Owner($owner_id = null)
	{
	}

	/**
	 * Add an event at current time or a datetime in the future
	 *
	 * @param int $type
	 * @param mixed $data
	 * @param string|DateTime $datetime (use database DATETIME format if string), current time if null
	 * @return DRY\Events\Event
	 */
	public function factory($type, $data, $datetime = null)
	{
	}

	/**
	 * Removes an event from the database, but only if the set owner is the actual owner of this event_id )
	 *
	 * @param int $event_id
	 */
	public function remove($event_id)
	{
	}

	/**
	 * Reads the list of stored events starting from time to the present time or a future time. In order to work properly, $to must be a higher datetime than $from
	 * @param string|DateTime $from
	 * @param string|DateTime $to
	 * @return \DRY\Record\Set A list of event objects
	 */
	public function read_Events($from, $to = null)
	{

	}

}

namespace DRY\Events;

/**
 * An Event object (which is actually a Single record, but with some extended functionality)
 *
 * @author Wavetrex <wavetrex@gmail.com>
 * @link http://www.donrey.net/Documentation/Structure/Modules/events.html
 * @license [GPL v3] http://www.gnu.org/licenses/gpl-3.0.html
 * @version 1.0.dev
 * @package DonReY
 * @subpackage Module/Events
 */
class Event extends \DRY\Record\Type_Single
{
	/**
	 * Sets the event as triggered ( accepts it )
	 */
	public function trigger()
	{
	}

	/**
	 * Encodes data into the "data" string using the preset algorithm (from config)
	 * If data is null, it stores a NULL in database
	 * @param mixed $data
	 */
	public function set_Data($data = null)
	{
	}

	/**
	 * Decodes the stored "data" using the preset algorithm
	 * If in database the data is a NULL, it returns null
	 * @return mixed
	 */
	public function get_Data()
	{
	}
}